import axios from 'axios';

import { server_base_url } from '../config';
import { info } from './common';

export const asset = {
    /**
     * 获取用户持仓记录接口
     */
    async getStockOrderList() {
        try {
            const token = localStorage.getItem('token');
            if (!token) throw new Error('token is null');
            const response = await axios.post(`${ server_base_url }/stock/orderList`, {}, {
                headers: { 'Content-Type': 'application/json', token }
            });
            const data = response.data;
            info('[ resposeData ] getStockOrderList', data);
            return { success: true, data };
        } catch (err) {
            info('[ err ] getStockOrderList', err);
            return { success: false, err };
        }
    },
    /**
     * 获取用户开仓记录接口
     */
    async getStockOpenList() {
        try {
            const token = localStorage.getItem('token');
            if (!token) throw new Error('token is null');
            const response = await axios.post(`${ server_base_url }/stock/openList`, {}, {
                headers: { 'Content-Type': 'application/json', token }
            });
            const data = response.data;
            info('[ resposeData ] getStockOpenList', data);
            return { success: true, data };
        } catch (err) {
            info('[ err ] getStockOpenList', err);
            return { success: false, err };
        }
    },
    /**
     * 获取用户平仓记录接口
     */
    async getStockCloseList() {
        try {
            const token = localStorage.getItem('token');
            if (!token) throw new Error('token is null');
            const response = await axios.post(`${ server_base_url }/stock/closeList`, {}, {
                headers: { 'Content-Type': 'application/json', token }
            });
            const data = response.data;
            info('[ resposeData ] getStockCloseList', data);
            return { success: true, data };
        } catch (err) {
            info('[ err ] getStockCloseList', err);
            return { success: false, err };
        }
    },
};
